package com.huixh.train.business.controller.admin;

import com.huixh.train.business.req.TrainQueryReq;
import com.huixh.train.business.req.TrainSaveReq;
import com.huixh.train.business.resp.TrainQueryResp;
import com.huixh.train.business.service.TrainSeatService;
import com.huixh.train.business.service.TrainService;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 先生成基础座位 在生成所有订单余票
 * @author huixh
 */
@Tag(name = "列车管理", description = "列车管理")
@Validated
@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {
    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;

    @PostMapping("/save")
    @Operation(summary = "保存列车信息或编辑", method = "POST")
    public Result<?> save(@RequestBody @Valid TrainSaveReq trainSaveReq) {
        trainService.save(trainSaveReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    @Operation(summary = "查询列车列表", method = "POST")
    public PageResult<List<TrainQueryResp>> query(@RequestBody @Valid TrainQueryReq trainQueryReq) {
        return trainService.queryList(trainQueryReq);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除列车信息", method = "DELETE")
    public Result<?> delete(@NotNull @PathVariable(name = "id") Long id) {
        trainService.delete(id);
        return Result.success("删除成功");
    }

    @GetMapping("/quest-all")
    @Operation(summary = "查询列车列表", method = "GET")
    public Result<List<TrainQueryResp>> query() {
        return trainService.queryList();
    }

    @Operation(summary = "生成座位数据", method = "GET")
    @GetMapping("/gen-seat/{trainCode}")
    public Result<String> genTrainSeat(@PathVariable(name = "trainCode") @NotBlank String trainCode) {
        trainSeatService.genTrainSeat(trainCode);
        return Result.success("生成成功");
    }
}